// service/FlightService.ts
import type { FlightData } from "../../types/DataTypes";
import { FlightDAO } from "../../DAO";

export class FlightService {
    // ==================== 航班操作 ====================

    // 新增航班
    static async addFlight(flight: FlightData): Promise<boolean> {
        return FlightDAO.addFlight(flight);
    }

    // 批量新增航班
   /* static async addFlights(flights: FlightData[]): Promise<number> {
        return FlightDAO.addFlights(flights);
    }*/

    // 获取所有航班
    static async getAllFlights(): Promise<FlightData[]> {
        return FlightDAO.getAllFlights();
    }

    // 根据航班号模糊查询航班
    static async searchFlightsByFlightNum(keyword: string): Promise<FlightData[]> {
        return FlightDAO.searchFlightsByFlightNum(keyword);
    }

    // 根据出发城市查询航班
    static async searchFlightsByFromCity(city: string): Promise<FlightData[]> {
        return FlightDAO.searchFlightsByFromCity(city);
    }

    // 根据到达城市查询航班
    static async searchFlightsByArivCity(city: string): Promise<FlightData[]> {
        return FlightDAO.searchFlightsByArivCity(city);
    }

    // 更新航班数据
    static async updateFlight(flightData: FlightData): Promise<boolean> {
        return FlightDAO.updateFlight(flightData);
    }

    static async checkFlightAvailability(flightNum: string): Promise<boolean> {
        const flight = await FlightDAO.getFlightByFlightNum(flightNum);
        return flight ? flight.availSeat > 0 : false;
    }

    // 可用座位数量+1
    static async incrementFlightAvailability(flightNum: string): Promise<boolean> {
        return await FlightDAO.incrementFlightAvailability(flightNum);
    }

    // 可用座位数量-1
    static async decrementFlightAvailability(flightNum: string): Promise<boolean> {
        return await FlightDAO.decrementFlightAvailability(flightNum);
    }

    // 删除航班
    static async deleteFlight(flightNum: string): Promise<boolean> {
        return FlightDAO.deleteFlight(flightNum);
    }

    //根据航班号精确查询航班
    static async getFlightByFlightNum(flightNum: string): Promise<FlightData | null> {
        return FlightDAO.getFlightByFlightNum(flightNum);
    }

    // 检查航班是否存在
    static async flightExists(flightNum: string): Promise<boolean> {
        return FlightDAO.flightExists(flightNum);
    }

    // 高级搜索（支持多个条件组合）
    static async advancedSearch(criteria: {
        flightNum?: string;
        fromCity?: string;
        arivCity?: string;
    }): Promise<FlightData[]> {
        return FlightDAO.advancedSearch(criteria);
    }


}